package com.tensquare.user.config;

import com.tensquare.user.interceptor.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: fxx
 * @Date: 2021/1/13 21:49
 */
@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

    @Autowired
    private JwtInterceptor jwtInterceptor;

    //添加拦截器
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {

        List<String> list = new ArrayList<>();
        list.add("/**/login/**");
        list.add("/**/register/**");
        //添加一个拦截器，以及要拦截的规则
        //这里将jwt拦截器注入进来
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/**") //拦截所有请求
                .excludePathPatterns(list);  //除了登录
    }
}
